﻿using System;
using DALHelper.DAL;
using System.Collections.Generic;

namespace DALHelper.Business
{
    public enum RoomStatus
    {
        Free,   // Y
        Busy,   // N
        Maintenance // X
    }

    public class Room
    {
        private DALManager m_DataManager;

        #region properties
        public string RoomID
        {
            get;
            set;
        }

        public int RoomCatID
        {
            get;
            set;
        }

        public RoomStatus RoomStatus
        {
            get;
            set;
        }

        public int Floor
        {
            get;
            set;
        } 
        #endregion

        public Room(DALManager dtManager)
        {
            m_DataManager = dtManager;

            // we will use m_DataManager.RoomDAL... in this class to query to database...
        }

        public Room()
        {
            RoomStatus = RoomStatus.Free;
        }

        public IEnumerable<RoomCategory> GetRoomFree(DateTime dtStart, DateTime dtEnd)
        {
            if (dtStart <= dtEnd)
            {
                return m_DataManager.RoomDAL.GetRoomFree(dtStart, dtEnd);
            }
            else
            {
                throw new Exception("Thoi diem tim kiem khong phu hop");
            }
        }

        public void CheckIn(long lTransID)
        {
            m_DataManager.RoomDAL.CheckIn(lTransID);
        }

        public void CheckOut(long lTransID)
        {
            m_DataManager.RoomDAL.CheckOut(lTransID);
        }

        public decimal Bill(long lTransID)
        {
            return m_DataManager.RoomDAL.Bill(lTransID);
        }

        public void Compensation(TransDetail[] tranDetails)
        {
            string sDetail = "";
            for (int i = 0; i < tranDetails.Length; i++)
			{
                sDetail += tranDetails[i].TransDetailID + ",";
                sDetail += tranDetails[i].CompensationFee + ",";
			}
            m_DataManager.RoomDAL.Compensation(tranDetails[0].TransactionID, sDetail);
        }
    }
}
